package niumao.minecraft.uhc.recipes;

import niumao.minecraft.uhc.Main;
import niumao.minecraft.uhc.Util;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;

public class recipeGui implements Listener {
    private static final int MAXSIZE = 9 * 6;
    private static final int DEFAULTPAGE = 1;
    private static final Main plugin = Main.getPlugin(Main.class);

    public static ItemStack BackGroundItem() {
        ItemStack item = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
        ItemMeta itemMeta = item.getItemMeta();
        assert itemMeta != null;
        itemMeta.setDisplayName(" ");
        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack RecipeBook() {
        ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
        ItemMeta itemMeta = item.getItemMeta();

        assert itemMeta != null;
        itemMeta.setLore(plugin.getConfig().getStringList("item." + Main.getLang() + ".RecipeBook.lore"));
        itemMeta.setDisplayName(plugin.getConfig().getString("item." + Main.getLang() + ".RecipeBook.name"));

        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack Close(int page) {
        ItemStack item = new ItemStack(Material.BARRIER);
        ItemMeta itemMeta = item.getItemMeta();

        assert itemMeta != null;
        itemMeta.setDisplayName(plugin.getConfig().getString("item." + Main.getLang()+ ".Close.name"));
        itemMeta.setCustomModelData(page);

        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack GoBack(int page) {
        ItemStack item = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = item.getItemMeta();

        assert itemMeta != null;
        itemMeta.setLore(plugin.getConfig().getStringList("item." + Main.getLang() + ".GoBack.lore"));
        itemMeta.setDisplayName(plugin.getConfig().getString("item." + Main.getLang() + ".GoBack.name"));
        itemMeta.setCustomModelData(page);

        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack NextPage(int page) {
        ItemStack item = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = item.getItemMeta();
        List<String> lore = plugin.getConfig().getStringList("item." + Main.getLang() + ".NextPage.lore");
        lore.set(0, lore.get(0) + (page + 1));

        assert itemMeta != null;
        itemMeta.setDisplayName(plugin.getConfig().getString("item." + Main.getLang() + ".NextPage.name"));
        itemMeta.setLore(lore);
        itemMeta.setCustomModelData(page + 1);

        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack PrePage(int page) {
        ItemStack item = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = item.getItemMeta();
        List<String> lore = plugin.getConfig().getStringList("item." + Main.getLang() + ".PrePage.lore");
        lore.set(0, lore.get(0) + (page - 1));

        assert itemMeta != null;
        itemMeta.setDisplayName(plugin.getConfig().getString("item." + Main.getLang() + ".PrePage.name"));
        itemMeta.setLore(lore);
        itemMeta.setCustomModelData(page - 1);

        item.setItemMeta(itemMeta);
        return item;
    }

    //玩家进入世界时给予一本配方书
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        ItemStack item = Util.checkInventory(event.getPlayer(), plugin.getConfig().getString("item." + Main.getLang() + ".RecipeBook.name"));
        if (item == null)
            event.getPlayer().getInventory().setItem(0, RecipeBook());
    }

    @EventHandler
    public void onPlayerClick(InventoryClickEvent event) {
        String title = plugin.getConfig().getString("item." + Main.getLang() + ".InventoryTitle.name");
        assert title != null;
        if (!event.getView().getTitle().contains(title)) return;
        ItemStack item = event.getCurrentItem();
        if (item == null) return;
        ItemMeta itemMeta = item.getItemMeta();
        if (itemMeta == null) return;
        Player player = (Player) event.getWhoClicked();

        //玩家不能移动配方书内的物品
        if (event.getView().getTitle().contains(title))
            event.setCancelled(true);

        //关闭面板
        if (itemMeta.getDisplayName().equals(plugin.getConfig().getString("item." + Main.getLang() + ".Close.name")))
            player.closeInventory();

        //返回上一级配方面板
        if (itemMeta.getDisplayName().equals(plugin.getConfig().getString("item." + Main.getLang() + ".GoBack.name")))
            baseInventory(player, itemMeta.getCustomModelData());

        //打开下一页的配方
        if (itemMeta.getDisplayName().equals(plugin.getConfig().getString("item." + Main.getLang() + ".NextPage.name")))
            baseInventory(player, itemMeta.getCustomModelData());

        //打开上一页的配方
        if (itemMeta.getDisplayName().equals(plugin.getConfig().getString("item." + Main.getLang() + ".PrePage.name")))
            baseInventory(player, itemMeta.getCustomModelData());

        //每个物品的配方
        for (int i = 0; i < UHCItem.allItems.size(); i++) {
            ItemStack recipeItem = UHCItem.allItems.get(i);
            ItemMeta recipeItemMeta = recipeItem.getItemMeta();
            assert recipeItemMeta != null;
            if (item.getItemMeta().getDisplayName().equals(recipeItem.getItemMeta().getDisplayName())) {
                recipeInventory(player, recipeItem, recipeItemMeta, i);
            }
        }
    }

    //右键配方书
    @EventHandler
    public void on(PlayerInteractEvent event) {
        if (event.getHand() == EquipmentSlot.HAND) {
            if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Player player = event.getPlayer();
                ItemMeta itemMeta = player.getInventory().getItemInMainHand().getItemMeta();
                if (itemMeta == null) return;
                if (itemMeta.getDisplayName().equals(plugin.getConfig().getString("item." + Main.getLang() + ".RecipeBook.name"))) {
                    baseInventory(player, DEFAULTPAGE);   //打开配方面板
                }
            }
        }
    }

    public void baseInventory(Player player, int page) {
        int finalPage = UHCItem.allItems.size() / 21 + 1;
        int counter = 21 * (page - 1);
        String title = plugin.getConfig().getString("item." + Main.getLang() + ".InventoryTitle.name");
        if (page != 1) title = "(" + page + "/" + finalPage + ") " + title;
        assert title != null;
        Inventory inventory = Bukkit.createInventory(player, MAXSIZE, title);
        inventory.setItem(49, Close(page));
        if (page != 1)
            inventory.setItem(45, PrePage(page));
        if (page != finalPage)
            inventory.setItem(53, NextPage(page));
        try {
            for (int i = 0; i < 7; i++)
                inventory.setItem(i + 10, UHCItem.allItems.get(counter++));
            for (int i = 0; i < 7; i++)
                inventory.setItem(i + 19, UHCItem.allItems.get(counter++));
            for (int i = 0; i < 7; i++)
                inventory.setItem(i + 28, UHCItem.allItems.get(counter++));
        } catch (IndexOutOfBoundsException ignored) {
        }
        player.openInventory(inventory);
    }

    public void recipeInventory(Player player, ItemStack item, ItemMeta itemMeta, int i) {
        UHCItem craftItems = new UHCItem();
        String title = plugin.getConfig().getString("item." + Main.getLang() + ".InventoryTitle.name");
        assert title != null;
        Inventory inventory = Bukkit.createInventory(player, MAXSIZE, title);
        for (int j = 0; j < MAXSIZE; j++)
            inventory.setItem(j, BackGroundItem());
        inventory.setItem(11, null);
        inventory.setItem(12, null);
        inventory.setItem(13, null);
        inventory.setItem(20, null);
        inventory.setItem(21, null);
        inventory.setItem(22, null);
        inventory.setItem(29, null);
        inventory.setItem(30, null);
        inventory.setItem(31, null);
        inventory.setItem(49, GoBack(i / 21 + 1));
        inventory.setItem(24, item);
        String name = itemMeta.getDisplayName();
        if (item.equals(craftItems.ApprenticeHelmet())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(20, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(22, new ItemStack(Material.IRON_INGOT));
        } else if (item.equals(craftItems.ApprenticeChestPlate())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(20, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(22, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(29, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(30, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        } else if (item.equals(craftItems.ApprenticeLeggings())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(20, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(22, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(29, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        } else if (item.equals(craftItems.ApprenticeBoots())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(20, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(22, new ItemStack(Material.IRON_INGOT));
        } else if (item.equals(craftItems.ApprenticeSword())) {
            inventory.setItem(12, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(21, new ItemStack(Material.IRON_SWORD));
            inventory.setItem(30, new ItemStack(Material.REDSTONE_BLOCK));
        } else if (item.equals(craftItems.ApprenticeBow())) {
            inventory.setItem(12, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(13, new ItemStack(Material.STRING));
            inventory.setItem(20, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(22, new ItemStack(Material.STRING));
            inventory.setItem(30, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(31, new ItemStack(Material.STRING));
        } else if (item.equals(craftItems.MasterCompass())) {
            inventory.setItem(11, new ItemStack(Material.REDSTONE));
            inventory.setItem(12, new ItemStack(Material.REDSTONE_TORCH));
            inventory.setItem(13, new ItemStack(Material.REDSTONE));
            inventory.setItem(20, new ItemStack(Material.REDSTONE));
            inventory.setItem(21, new ItemStack(Material.COMPASS));
            inventory.setItem(22, new ItemStack(Material.REDSTONE));
            inventory.setItem(29, new ItemStack(Material.REDSTONE));
            inventory.setItem(30, new ItemStack(Material.REDSTONE));
            inventory.setItem(31, new ItemStack(Material.REDSTONE));
        } else if (item.equals(craftItems.VorpalSword())) {
            inventory.setItem(12, new ItemStack(Material.BONE));
            inventory.setItem(21, new ItemStack(Material.IRON_SWORD));
            inventory.setItem(30, new ItemStack(Material.ROTTEN_FLESH));
        } else if (item.equals(craftItems.Sharpness())) {
            inventory.setItem(11, new ItemStack(Material.FLINT));
            inventory.setItem(21, new ItemStack(Material.PAPER));
            inventory.setItem(22, new ItemStack(Material.PAPER));
            inventory.setItem(30, new ItemStack(Material.PAPER));
            inventory.setItem(31, new ItemStack(Material.IRON_SWORD));
        } else if (name.equals(Util.getStr("DragonSword"))) {
            inventory.setItem(12, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_SWORD));
            inventory.setItem(29, new ItemStack(Material.OBSIDIAN));
            inventory.setItem(30, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(31, new ItemStack(Material.OBSIDIAN));
        } else if (item.equals(craftItems.Protection())) {
            inventory.setItem(21, new ItemStack(Material.PAPER));
            inventory.setItem(22, new ItemStack(Material.PAPER));
            inventory.setItem(30, new ItemStack(Material.PAPER));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        } else if (item.equals(craftItems.Projectile_Protection())) {
            inventory.setItem(21, new ItemStack(Material.PAPER));
            inventory.setItem(22, new ItemStack(Material.PAPER));
            inventory.setItem(30, new ItemStack(Material.PAPER));
            inventory.setItem(31, new ItemStack(Material.ARROW));
        } else if (item.equals(craftItems.DragonArmor())) {
            inventory.setItem(12, new ItemStack(Material.MAGMA_CREAM));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_CHESTPLATE));
            inventory.setItem(29, new ItemStack(Material.OBSIDIAN));
            inventory.setItem(30, new ItemStack(Material.ANVIL));
            inventory.setItem(31, new ItemStack(Material.OBSIDIAN));
        } else if (item.equals(craftItems.SpikedArmor())) {
            inventory.setItem(12, new ItemStack(Material.LILY_PAD));
            inventory.setItem(21, new ItemStack(Material.CACTUS));
            inventory.setItem(30, new ItemStack(Material.LEATHER_CHESTPLATE));
        } else if (item.equals(craftItems.SevenLeagueBoots())) {
            inventory.setItem(11, new ItemStack(Material.FEATHER));
            inventory.setItem(12, new ItemStack(Material.ENDER_PEARL));
            inventory.setItem(13, new ItemStack(Material.FEATHER));
            inventory.setItem(20, new ItemStack(Material.FEATHER));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_BOOTS));
            inventory.setItem(22, new ItemStack(Material.FEATHER));
            inventory.setItem(29, new ItemStack(Material.FEATHER));
            inventory.setItem(30, new ItemStack(Material.WATER_BUCKET));
            inventory.setItem(31, new ItemStack(Material.FEATHER));
        } else if (item.equals(craftItems.TarnHelm())) {
            inventory.setItem(11, new ItemStack(Material.DIAMOND));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.DIAMOND));
            inventory.setItem(20, new ItemStack(Material.DIAMOND));
            inventory.setItem(21, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(22, new ItemStack(Material.DIAMOND));
        } else if (item.equals(craftItems.PhilosopherPickAxe())) {
            inventory.setItem(11, new ItemStack(Material.IRON_ORE));
            inventory.setItem(12, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(13, new ItemStack(Material.IRON_ORE));
            inventory.setItem(20, new ItemStack(Material.LAPIS_BLOCK));
            inventory.setItem(21, new ItemStack(Material.STICK));
            inventory.setItem(22, new ItemStack(Material.LAPIS_BLOCK));
            inventory.setItem(30, new ItemStack(Material.STICK));
        } else if (item.equals(craftItems.Velocity())) {
            inventory.setItem(12, new ItemStack(Material.COCOA_BEANS));
            inventory.setItem(21, new ItemStack(Material.SUGAR));
            inventory.setItem(30, new ItemStack(Material.GLASS_BOTTLE));
        } else if (item.equals(craftItems.IronPickaxe())) {
            inventory.setItem(11, new ItemStack(Material.IRON_ORE));
            inventory.setItem(12, new ItemStack(Material.IRON_ORE));
            inventory.setItem(13, new ItemStack(Material.IRON_ORE));
            inventory.setItem(20, new ItemStack(Material.COAL));
            inventory.setItem(21, new ItemStack(Material.STICK));
            inventory.setItem(22, new ItemStack(Material.COAL));
            inventory.setItem(30, new ItemStack(Material.STICK));
        } else if (item.equals(craftItems.LumberAxe())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.FLINT));
            inventory.setItem(20, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.STICK));
            inventory.setItem(30, new ItemStack(Material.STICK));
        } else if (item.equals(craftItems.FlaskofIchor())) {
            inventory.setItem(12, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(20, new ItemStack(Material.BROWN_MUSHROOM));
            inventory.setItem(21, new ItemStack(Material.GLASS_BOTTLE));
            inventory.setItem(22, new ItemStack(Material.BROWN_MUSHROOM));
            inventory.setItem(30, new ItemStack(Material.INK_SAC));
        } else if (item.equals(craftItems.Exodus())) {
            inventory.setItem(11, new ItemStack(Material.DIAMOND));
            inventory.setItem(12, new ItemStack(Material.DIAMOND));
            inventory.setItem(13, new ItemStack(Material.DIAMOND));
            inventory.setItem(20, new ItemStack(Material.DIAMOND));
            inventory.setItem(21, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(22, new ItemStack(Material.DIAMOND));
            inventory.setItem(29, new ItemStack(Material.EMERALD));
            inventory.setItem(30, new ItemStack(Material.GOLDEN_CARROT));
            inventory.setItem(31, new ItemStack(Material.EMERALD));
        } else if (item.equals(craftItems.Leviathan())) {
            inventory.setItem(11, new ItemStack(Material.LAPIS_BLOCK));
            inventory.setItem(12, new ItemStack(Material.WATER_BUCKET));
            inventory.setItem(13, new ItemStack(Material.LAPIS_BLOCK));
            inventory.setItem(20, new ItemStack(Material.DIAMOND));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_LEGGINGS));
            inventory.setItem(22, new ItemStack(Material.DIAMOND));
            inventory.setItem(29, new ItemStack(Material.LILY_PAD));
            inventory.setItem(31, new ItemStack(Material.LILY_PAD));
        } else if (item.equals(craftItems.Perun())) {
            inventory.setItem(11, new ItemStack(Material.DIAMOND));
            inventory.setItem(12, new ItemStack(Material.TNT));
            inventory.setItem(13, new ItemStack(Material.FIRE_CHARGE));
            inventory.setItem(20, new ItemStack(Material.DIAMOND));
            inventory.setItem(21, new ItemStack(Material.STICK));
            inventory.setItem(30, new ItemStack(Material.STICK));
        } else if (item.equals(craftItems.Excalibur())) {
            inventory.setItem(11, new ItemStack(Material.SOUL_SAND));
            inventory.setItem(12, new ItemStack(Material.FIRE_CHARGE));
            inventory.setItem(13, new ItemStack(Material.SOUL_SAND));
            inventory.setItem(20, new ItemStack(Material.SOUL_SAND));
            inventory.setItem(21, new ItemStack(Material.TNT));
            inventory.setItem(22, new ItemStack(Material.SOUL_SAND));
            inventory.setItem(29, new ItemStack(Material.SOUL_SAND));
            inventory.setItem(30, new ItemStack(Material.DIAMOND_SWORD));
            inventory.setItem(31, new ItemStack(Material.SOUL_SAND));
        } else if (item.equals(craftItems.Anduril())) {
            inventory.setItem(11, new ItemStack(Material.FEATHER));
            inventory.setItem(12, new ItemStack(Material.IRON_BLOCK));
            inventory.setItem(13, new ItemStack(Material.FEATHER));
            inventory.setItem(20, new ItemStack(Material.FEATHER));
            inventory.setItem(21, new ItemStack(Material.IRON_BLOCK));
            inventory.setItem(22, new ItemStack(Material.FEATHER));
            inventory.setItem(29, new ItemStack(Material.FEATHER));
            inventory.setItem(30, new ItemStack(Material.BLAZE_ROD));
            inventory.setItem(31, new ItemStack(Material.FEATHER));
        } else if (item.equals(craftItems.Scythe())) {
            inventory.setItem(12, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(13, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(21, new ItemStack(Material.BONE));
            inventory.setItem(22, new ItemStack(Material.CLOCK));
            inventory.setItem(29, new ItemStack(Material.BONE));
        } else if (item.equals(craftItems.Machina())) {
            inventory.setItem(12, new ItemStack(Material.EMERALD));
            inventory.setItem(21, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(30, new ItemStack(Material.GLASS_BOTTLE));
        } else if (item.equals(craftItems.KingofRod())) {
            inventory.setItem(12, new ItemStack(Material.FISHING_ROD));
            inventory.setItem(20, new ItemStack(Material.LILY_PAD));
            inventory.setItem(21, new ItemStack(Material.COMPASS));
            inventory.setItem(22, new ItemStack(Material.LILY_PAD));
            inventory.setItem(30, new ItemStack(Material.WATER_BUCKET));
        } else if (item.equals(craftItems.Vidar())) {
            inventory.setItem(12, new ItemStack(Material.PUFFERFISH));
            inventory.setItem(20, new ItemStack(Material.POTION));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_BOOTS));
            inventory.setItem(22, new ItemStack(Material.POTION));
            inventory.setItem(30, new ItemStack(Material.FISHING_ROD));
        } else if (item.equals(craftItems.Vitality())) {
            inventory.setItem(12, new ItemStack(Material.WITHER_SKELETON_SKULL));
            inventory.setItem(21, new ItemStack(Material.NETHER_WART));
            inventory.setItem(30, new ItemStack(Material.GLASS_BOTTLE));
        } else if (item.equals(craftItems.Miner())) {
            inventory.setItem(11, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(12, new ItemStack(Material.IRON_SWORD));
            inventory.setItem(13, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(20, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_PICKAXE));
            inventory.setItem(22, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(29, new ItemStack(Material.BOOKSHELF));
            inventory.setItem(30, new ItemStack(Material.BOOKSHELF));
            inventory.setItem(31, new ItemStack(Material.BOOKSHELF));
        } else if (item.equals(craftItems.Bloodlust())) {
            inventory.setItem(11, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(12, new ItemStack(Material.DIAMOND));
            inventory.setItem(13, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(20, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_SWORD));
            inventory.setItem(22, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(29, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(30, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(31, new ItemStack(Material.REDSTONE_BLOCK));
        } else if (item.equals(craftItems.Modular())) {
            inventory.setItem(12, new ItemStack(Material.CLOCK));
            inventory.setItem(20, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(21, new ItemStack(Material.BOW));
            inventory.setItem(22, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(29, new ItemStack(Material.SPIDER_EYE));
            inventory.setItem(30, new ItemStack(Material.SLIME_BALL));
            inventory.setItem(31, new ItemStack(Material.SPIDER_EYE));
        } else if (item.equals(craftItems.Hermes())) {
            inventory.setItem(11, new ItemStack(Material.DIAMOND));
            inventory.setItem(12, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(13, new ItemStack(Material.DIAMOND));
            inventory.setItem(20, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_BOOTS));
            inventory.setItem(22, new ItemStack(Material.BLAZE_POWDER));
            inventory.setItem(29, new ItemStack(Material.FEATHER));
            inventory.setItem(31, new ItemStack(Material.FEATHER));
        } else if (item.equals(craftItems.Barbarian())) {
            inventory.setItem(20, new ItemStack(Material.BLAZE_ROD));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_CHESTPLATE));
            inventory.setItem(22, new ItemStack(Material.BLAZE_ROD));
            inventory.setItem(29, new ItemStack(Material.IRON_BLOCK));
            ItemStack stpot = new ItemStack(Material.POTION, 1, (short) 9);
            ItemMeta meta = stpot.getItemMeta();
            assert meta != null;
            meta.setDisplayName("Potion of Strength");
            stpot.setItemMeta(meta);
            inventory.setItem(30, stpot);
            inventory.setItem(31, new ItemStack(Material.IRON_BLOCK));
        } else if (item.equals(craftItems.Cupid())) {
            inventory.setItem(12, new ItemStack(Material.BLAZE_ROD));
            inventory.setItem(20, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(21, new ItemStack(Material.BOW));
            inventory.setItem(22, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(30, new ItemStack(Material.LAVA_BUCKET));
        } else if (item.equals(craftItems.Artemis())) {
            inventory.setItem(11, new ItemStack(Material.FEATHER));
            inventory.setItem(12, new ItemStack(Material.DIAMOND));
            inventory.setItem(13, new ItemStack(Material.FEATHER));
            inventory.setItem(20, new ItemStack(Material.FEATHER));
            inventory.setItem(21, new ItemStack(Material.BOW));
            inventory.setItem(22, new ItemStack(Material.FEATHER));
            inventory.setItem(29, new ItemStack(Material.FEATHER));
            inventory.setItem(30, new ItemStack(Material.ENDER_EYE));
            inventory.setItem(31, new ItemStack(Material.FEATHER));
        } else if (item.equals(craftItems.GoldenHead())) {
            inventory.setItem(11, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(12, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(13, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(20, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(21, new ItemStack(Material.PLAYER_HEAD));
            inventory.setItem(22, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(29, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(30, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(31, new ItemStack(Material.GOLD_INGOT));
        } else if (item.equals(craftItems.Power())) {
            inventory.setItem(11, new ItemStack(Material.FLINT));
            inventory.setItem(21, new ItemStack(Material.PAPER));
            inventory.setItem(22, new ItemStack(Material.PAPER));
            inventory.setItem(30, new ItemStack(Material.PAPER));
            inventory.setItem(31, new ItemStack(Material.BONE));
        }else if (item.equals(craftItems.FusionArmor())) {
            inventory.setItem(11, new ItemStack(Material.DIAMOND_HELMET));
            inventory.setItem(12, new ItemStack(Material.DIAMOND_CHESTPLATE));
            inventory.setItem(13, new ItemStack(Material.DIAMOND_LEGGINGS));
            inventory.setItem(20, new ItemStack(Material.DIAMOND_LEGGINGS));
            inventory.setItem(21, new ItemStack(Material.DIAMOND_BOOTS));
        }else if (item.equals(craftItems.Nectar())) {
            inventory.setItem(12, new ItemStack(Material.EMERALD));
            inventory.setItem(20, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(21, new ItemStack(Material.MELON_SLICE));
            inventory.setItem(22, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(30, new ItemStack(Material.GLASS_BOTTLE));
        }else if (item.equals(craftItems.Cornucopia())) {
            inventory.setItem(11, new ItemStack(Material.CARROT));
            inventory.setItem(12, new ItemStack(Material.CARROT));
            inventory.setItem(13, new ItemStack(Material.CARROT));
            inventory.setItem(20, new ItemStack(Material.CARROT));
            inventory.setItem(21, new ItemStack(Material.GOLDEN_APPLE));
            inventory.setItem(22, new ItemStack(Material.CARROT));
            inventory.setItem(29, new ItemStack(Material.CARROT));
            inventory.setItem(30, new ItemStack(Material.CARROT));
            inventory.setItem(31, new ItemStack(Material.CARROT));
        }else if (item.equals(craftItems.LeatherEconomy())) {
            inventory.setItem(11, new ItemStack(Material.STICK));
            inventory.setItem(12, new ItemStack(Material.LEATHER));
            inventory.setItem(13, new ItemStack(Material.STICK));
            inventory.setItem(20, new ItemStack(Material.STICK));
            inventory.setItem(21, new ItemStack(Material.LEATHER));
            inventory.setItem(22, new ItemStack(Material.STICK));
            inventory.setItem(29, new ItemStack(Material.STICK));
            inventory.setItem(30, new ItemStack(Material.LEATHER));
            inventory.setItem(31, new ItemStack(Material.STICK));
        }else if (item.equals(craftItems.DustOfLight())) {
            inventory.setItem(11, new ItemStack(Material.REDSTONE));
            inventory.setItem(12, new ItemStack(Material.REDSTONE));
            inventory.setItem(13, new ItemStack(Material.REDSTONE));
            inventory.setItem(20, new ItemStack(Material.REDSTONE));
            inventory.setItem(21, new ItemStack(Material.FLINT_AND_STEEL));
            inventory.setItem(22, new ItemStack(Material.REDSTONE));
            inventory.setItem(29, new ItemStack(Material.REDSTONE));
            inventory.setItem(30, new ItemStack(Material.REDSTONE));
            inventory.setItem(31, new ItemStack(Material.REDSTONE));
        }else if (item.equals(craftItems.BrewingArtifact())) {
            inventory.setItem(12, new ItemStack(Material.WHEAT_SEEDS));
            inventory.setItem(20, new ItemStack(Material.WHEAT_SEEDS));
            inventory.setItem(21, new ItemStack(Material.FERMENTED_SPIDER_EYE));
            inventory.setItem(22, new ItemStack(Material.WHEAT_SEEDS));
            inventory.setItem(30, new ItemStack(Material.WHEAT_SEEDS));
        }else if (item.equals(craftItems.DeliciousSteak())) {
            inventory.setItem(11, new ItemStack(Material.BEEF));
            inventory.setItem(12, new ItemStack(Material.BEEF));
            inventory.setItem(13, new ItemStack(Material.BEEF));
            inventory.setItem(20, new ItemStack(Material.BEEF));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.BEEF));
            inventory.setItem(29, new ItemStack(Material.BEEF));
            inventory.setItem(30, new ItemStack(Material.BEEF));
            inventory.setItem(31, new ItemStack(Material.BEEF));
        }else if (item.equals(craftItems.DeliciousPorkChop())) {
            inventory.setItem(11, new ItemStack(Material.PORKCHOP));
            inventory.setItem(12, new ItemStack(Material.PORKCHOP));
            inventory.setItem(13, new ItemStack(Material.PORKCHOP));
            inventory.setItem(20, new ItemStack(Material.PORKCHOP));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.PORKCHOP));
            inventory.setItem(29, new ItemStack(Material.PORKCHOP));
            inventory.setItem(30, new ItemStack(Material.PORKCHOP));
            inventory.setItem(31, new ItemStack(Material.PORKCHOP));
        }else if (item.equals(craftItems.DeliciousMutton())) {
            inventory.setItem(11, new ItemStack(Material.MUTTON));
            inventory.setItem(12, new ItemStack(Material.MUTTON));
            inventory.setItem(13, new ItemStack(Material.MUTTON));
            inventory.setItem(20, new ItemStack(Material.MUTTON));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.MUTTON));
            inventory.setItem(29, new ItemStack(Material.MUTTON));
            inventory.setItem(30, new ItemStack(Material.MUTTON));
            inventory.setItem(31, new ItemStack(Material.MUTTON));
        }else if (item.equals(craftItems.DeliciousChicken())) {
            inventory.setItem(11, new ItemStack(Material.CHICKEN));
            inventory.setItem(12, new ItemStack(Material.CHICKEN));
            inventory.setItem(13, new ItemStack(Material.CHICKEN));
            inventory.setItem(20, new ItemStack(Material.CHICKEN));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.CHICKEN));
            inventory.setItem(29, new ItemStack(Material.CHICKEN));
            inventory.setItem(30, new ItemStack(Material.CHICKEN));
            inventory.setItem(31, new ItemStack(Material.CHICKEN));
        }else if (item.equals(craftItems.DeliciousRabbit())) {
            inventory.setItem(11, new ItemStack(Material.RABBIT));
            inventory.setItem(12, new ItemStack(Material.RABBIT));
            inventory.setItem(13, new ItemStack(Material.RABBIT));
            inventory.setItem(20, new ItemStack(Material.RABBIT));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.RABBIT));
            inventory.setItem(29, new ItemStack(Material.RABBIT));
            inventory.setItem(30, new ItemStack(Material.RABBIT));
            inventory.setItem(31, new ItemStack(Material.RABBIT));
        }else if (item.equals(craftItems.DeliciousCod())) {
            inventory.setItem(11, new ItemStack(Material.COD));
            inventory.setItem(12, new ItemStack(Material.COD));
            inventory.setItem(13, new ItemStack(Material.COD));
            inventory.setItem(20, new ItemStack(Material.COD));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.COD));
            inventory.setItem(29, new ItemStack(Material.COD));
            inventory.setItem(30, new ItemStack(Material.COD));
            inventory.setItem(31, new ItemStack(Material.COD));
        }else if (item.equals(craftItems.DeliciousSalmon())) {
            inventory.setItem(11, new ItemStack(Material.SALMON));
            inventory.setItem(12, new ItemStack(Material.SALMON));
            inventory.setItem(13, new ItemStack(Material.SALMON));
            inventory.setItem(20, new ItemStack(Material.SALMON));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.SALMON));
            inventory.setItem(29, new ItemStack(Material.SALMON));
            inventory.setItem(30, new ItemStack(Material.SALMON));
            inventory.setItem(31, new ItemStack(Material.SALMON));
        }else if (item.equals(craftItems.FlamingArtifact())) {
            inventory.setItem(11, new ItemStack(Material.ORANGE_STAINED_GLASS));
            inventory.setItem(12, new ItemStack(Material.LAVA_BUCKET));
            inventory.setItem(13, new ItemStack(Material.ORANGE_STAINED_GLASS));
            inventory.setItem(20, new ItemStack(Material.ORANGE_STAINED_GLASS));
            inventory.setItem(21, new ItemStack(Material.FIREWORK_ROCKET));
            inventory.setItem(22, new ItemStack(Material.ORANGE_STAINED_GLASS));
            inventory.setItem(29, new ItemStack(Material.ORANGE_STAINED_GLASS));
            inventory.setItem(30, new ItemStack(Material.LAVA_BUCKET));
            inventory.setItem(31, new ItemStack(Material.ORANGE_STAINED_GLASS));
        }else if (item.equals(craftItems.IronPack())) {
            inventory.setItem(11, new ItemStack(Material.IRON_ORE));
            inventory.setItem(12, new ItemStack(Material.IRON_ORE));
            inventory.setItem(13, new ItemStack(Material.IRON_ORE));
            inventory.setItem(20, new ItemStack(Material.IRON_ORE));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.IRON_ORE));
            inventory.setItem(29, new ItemStack(Material.IRON_ORE));
            inventory.setItem(30, new ItemStack(Material.IRON_ORE));
            inventory.setItem(31, new ItemStack(Material.IRON_ORE));
        }else if (item.equals(craftItems.Obsidian())) {
            inventory.setItem(21, new ItemStack(Material.WATER_BUCKET));
            inventory.setItem(30, new ItemStack(Material.LAVA_BUCKET));
        }else if (item.equals(craftItems.EnlighteningPack())) {
            inventory.setItem(12, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(20, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(21, new ItemStack(Material.GLASS_BOTTLE));
            inventory.setItem(22, new ItemStack(Material.REDSTONE_BLOCK));
            inventory.setItem(30, new ItemStack(Material.REDSTONE_BLOCK));
        }else if (item.equals(craftItems.IronPack())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.IRON_BLOCK));
            inventory.setItem(29, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(30, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        }else if (item.equals(craftItems.LightAnvil())) {
            inventory.setItem(11, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(12, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(13, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(21, new ItemStack(Material.IRON_BLOCK));
            inventory.setItem(29, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(30, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        }else if (item.equals(craftItems.LightEnchantmentTable())) {
            inventory.setItem(12, new ItemStack(Material.BOOKSHELF));
            inventory.setItem(20, new ItemStack(Material.OBSIDIAN));
            inventory.setItem(21, new ItemStack(Material.DIAMOND));
            inventory.setItem(22, new ItemStack(Material.OBSIDIAN));
            inventory.setItem(29, new ItemStack(Material.OBSIDIAN));
            inventory.setItem(30, new ItemStack(Material.EXPERIENCE_BOTTLE));
            inventory.setItem(31, new ItemStack(Material.OBSIDIAN));
        }else if (item.equals(craftItems.Temptation())) {
            inventory.setItem(21, new ItemStack(Material.BONE_MEAL));
            inventory.setItem(30, new ItemStack(Material.APPLE));
        }else if (item.equals(craftItems.LightApple())) {
            inventory.setItem(12, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(20, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(21, new ItemStack(Material.APPLE));
            inventory.setItem(22, new ItemStack(Material.GOLD_INGOT));
            inventory.setItem(30, new ItemStack(Material.GOLD_INGOT));
        }else if (item.equals(craftItems.LightEnchantingApple())) {
            inventory.setItem(12, new ItemStack(Material.GOLD_BLOCK));
            inventory.setItem(20, new ItemStack(Material.GOLD_BLOCK));
            inventory.setItem(21, new ItemStack(Material.GOLDEN_APPLE));
            inventory.setItem(22, new ItemStack(Material.GOLD_BLOCK));
            inventory.setItem(30, new ItemStack(Material.GOLD_BLOCK));
        }else if (item.equals(craftItems.ArrowEconomy())) {
            inventory.setItem(11, new ItemStack(Material.FLINT));
            inventory.setItem(12, new ItemStack(Material.FLINT));
            inventory.setItem(13, new ItemStack(Material.FLINT));
            inventory.setItem(20, new ItemStack(Material.STICK));
            inventory.setItem(21, new ItemStack(Material.STICK));
            inventory.setItem(22, new ItemStack(Material.STICK));
            inventory.setItem(29, new ItemStack(Material.FEATHER));
            inventory.setItem(30, new ItemStack(Material.FEATHER));
            inventory.setItem(31, new ItemStack(Material.FEATHER));
        }else if (item.equals(craftItems.Saddle())) {
            inventory.setItem(11, new ItemStack(Material.LEATHER));
            inventory.setItem(12, new ItemStack(Material.LEATHER));
            inventory.setItem(13, new ItemStack(Material.LEATHER));
            inventory.setItem(20, new ItemStack(Material.STRING));
            inventory.setItem(21, new ItemStack(Material.LEATHER));
            inventory.setItem(22, new ItemStack(Material.STRING));
            inventory.setItem(29, new ItemStack(Material.IRON_INGOT));
            inventory.setItem(31, new ItemStack(Material.IRON_INGOT));
        }else if (item.equals(craftItems.GoldPack())) {
            inventory.setItem(11, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(12, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(13, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(20, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(21, new ItemStack(Material.COAL_BLOCK));
            inventory.setItem(22, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(29, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(30, new ItemStack(Material.GOLD_ORE));
            inventory.setItem(31, new ItemStack(Material.GOLD_ORE));
        }else if (item.equals(craftItems.SugarRush())) {
            inventory.setItem(12, new ItemStack(Material.OAK_SAPLING));
            inventory.setItem(20, new ItemStack(Material.WHEAT_SEEDS));
            inventory.setItem(21, new ItemStack(Material.SUGAR));
            inventory.setItem(22, new ItemStack(Material.WHEAT_SEEDS));
        }else if (item.equals(craftItems.Elytra())) {
            inventory.setItem(11, new ItemStack(Material.PHANTOM_MEMBRANE));
            inventory.setItem(12, new ItemStack(Material.SHULKER_SHELL));
            inventory.setItem(13, new ItemStack(Material.PHANTOM_MEMBRANE));
            inventory.setItem(20, new ItemStack(Material.PHANTOM_MEMBRANE));
            inventory.setItem(21, new ItemStack(Material.SADDLE));
            inventory.setItem(22, new ItemStack(Material.PHANTOM_MEMBRANE));
            inventory.setItem(29, new ItemStack(Material.PHANTOM_MEMBRANE));
            inventory.setItem(30, new ItemStack(Material.SHULKER_SHELL));
            inventory.setItem(31, new ItemStack(Material.PHANTOM_MEMBRANE));
        }
        player.openInventory(inventory);
    }
}
